#include "messageeditarea.h"
#include <QGridLayout>
#include <QLineEdit>
#include <QPlainTextEdit>
#include <QPushButton>
#include <QSizePolicy>
#include <QTextEdit>
#include <qscrollbar.h>
#include"historymessagedialog.h"
MessageEditArea::MessageEditArea(QWidget *parent)
    : QWidget(parent)
{

    QString btnstyle("QPushButton {"
                     "   border: none;"
                     "   border-radius: 8px;"
                     "   background: qlineargradient(135deg, #ff6b6b, #ffa36c);"
                     "}"
                     "QPushButton:hover {"
                     "   background: qlineargradient(135deg, #ff9e9e, #ffc99c);"  // 更亮的悬停颜色
                     "   border: 2px solid rgba(255, 255, 255, 0.5);"  // 添加白色边框增强效果
                     "}"
                     "QPushButton:pressed {"
                     "   background: qlineargradient(135deg, #ffd1d1, #ffe0c2);"  // 更亮的按下颜色
                     "   border: 2px solid rgba(255, 255, 255, 0.8);"  // 更明显的边框
                     "}");
    this->setMinimumHeight(150);
    this->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    this->setObjectName("messageeditarea");
    this->setStyleSheet("#messageeditarea{background:transparent;border:none;}");

    // 创建整体的垂直布局管理器
    QVBoxLayout *layout = new QVBoxLayout();
    layout->setSpacing(0);
    layout->setContentsMargins(0, 0, 0, 0);
    this->setLayout(layout);

    // 创建图片按钮
    QPushButton *picturebtn = new QPushButton();
    picturebtn->setFixedSize(30, 30);
    picturebtn->setIcon(QIcon(":/Resources/picturebtn.png"));
    picturebtn->setIconSize(QSize(25, 25));
    picturebtn->setStyleSheet(btnstyle);

    // 创建文件按钮
    QPushButton *filebtn = new QPushButton();
    filebtn->setFixedSize(30, 30);
    filebtn->setIcon(QIcon(":/Resources/filebtn.png"));
    filebtn->setIconSize(QSize(25, 25));
    filebtn->setStyleSheet(btnstyle);

    // 创建语音按钮
    QPushButton *spechbtn = new QPushButton();
    spechbtn->setFixedSize(30, 30);
    spechbtn->setIcon(QIcon(":/Resources/spechbtn.png"));
    spechbtn->setIconSize(QSize(25, 25));
    spechbtn->setStyleSheet(btnstyle);

    // 创建历史消息按钮
    QPushButton *historybtn = new QPushButton();
    historybtn->setFixedSize(30, 30);
    historybtn->setIcon(QIcon(":/Resources/historybtn.png"));
    historybtn->setIconSize(QSize(25, 25));
    historybtn->setStyleSheet(btnstyle);

    // 创建水平布局管理器进行按钮管理
    QHBoxLayout *firstLayout = new QHBoxLayout();
    firstLayout->setSpacing(0);
    firstLayout->setContentsMargins(0, 0, 0, 0);
    firstLayout->addWidget(picturebtn);
    firstLayout->addWidget(filebtn);
    firstLayout->addWidget(spechbtn);
    firstLayout->addWidget(historybtn);
    firstLayout->addStretch(1);


    QPlainTextEdit *secondwidget = new QPlainTextEdit();
    secondwidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    secondwidget->setStyleSheet(
        "QPlainTextEdit {"
        "   border: none;"
        "   background-color: rgba(45, 45, 65, 0.5);"  // 半透明深色背景
        "   font-size: 14px;"
        "   padding: 10px;"
        "   color: #e0e0e0;"  // 浅色文本
        "   border-radius: 8px;"  // 圆角
        "   margin: 5px 10px;"  // 外边距
        "   selection-background-color: rgba(255, 107, 107, 0.3);"  // 选中文本背景色
        "}"
        "QPlainTextEdit:focus {"
        "   background-color: rgba(55, 55, 75, 0.7);"  // 焦点时加深背景
        "   border: 1px solid rgba(255, 107, 107, 0.5);"  // 焦点时边框
        "}");
    secondwidget->verticalScrollBar()->setStyleSheet(
        "QScrollBar:vertical {"
        "   width: 8px;"
        "   background: rgba(255, 255, 255, 0.05);"
        "   border-radius: 4px;"
        "}"
        "QScrollBar::handle:vertical {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "               stop:0 #ff6b6b, stop:1 #06d6a0);"
        "   border-radius: 4px;"
        "   min-height: 30px;"
        "}"
        "QScrollBar::handle:vertical:hover {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "               stop:0 #ff8e8e, stop:1 #08e6b0);"
        "}");
    // 添加到主布局
    layout->addLayout(firstLayout);
    layout->addWidget(secondwidget, 1); // 第二个参数是拉伸因子，确保编辑框占据剩余空间





    connect(historybtn,&QPushButton::clicked,this,[=](){
        HistoryMessageDialog*dialog=new HistoryMessageDialog();
        dialog->exec();
    });
}
